<?php

/**
 * Project form base class.
 *
 * @package    maximous
 * @subpackage form
 * @author     Mina.Gerges.Wadea
 * @version    SVN: $Id: sfDoctrineFormBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class BaseFormDoctrine extends sfFormDoctrine
{

    public function setup()
    {
        
    }

    /**
     * check if tha login user can controle the statues field or need_check fild 
     */
    public function configureLoginUserRoleOnChangeStatusAndNeedCheck()
    {
        $maxUser = $this->getOption('maxUser');
        if (!$maxUser instanceof MaxUser)
        {
            throw new InvalidArgumentException('to use checkLoginUserRoleOnChangeStatusAndNeedCheck() you need to set maxUser object in form options');
        }
        // check if user can change statues     
        if (isset($this['statues']))
        {
            if ($maxUser->getMaxUserRole()->canChangeStatus())
            {
                $class     = $this->getModelName();
                $modelName = new $class;
                $statues   = $modelName->getStatuesArray();
                if ($maxUser->getMaxUserRole()->isUser())
                {
                    if (isset($statues[3]))
                        unset($statues[3]);
                }

                $this->setWidget('statues', new sfWidgetFormChoice(array('choices' => $statues)));
                $this->setValidator('statues', new sfValidatorChoice(array('choices' => array_keys($statues))));
            }
            else
            {
                unset($this['statues']);
            }
        }
        // check if user can change statues 
        if ($maxUser->getMaxUserRole()->canCheck())
        {
            
        }
        else
        {
            unset($this['need_check']);
        }
    }

}

